package com.bj.disc.ui.main.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.ai3d.rfid.base.vm.BaseViewModel
import com.ai3d.rfid.common.log.Logcat
import com.ai3d.rfid.network.proxy.NetworkProxy
import com.bj.disc.ui.login.bean.LoginUserInfo
import kotlinx.coroutines.launch

/**
 * @ProjectName : Kolb
 * @Author : weijinsong
 * @Time : 2022/12/30 14:36
 * @Description : 文件描述
 */
class MainViewModel : BaseViewModel() {
    private val TAG = "MainViewModel"
    var goMain = MutableLiveData(false)
    var exitLMD = MutableLiveData<Boolean>()
    var loginUserInfo = MutableLiveData<LoginUserInfo>()

    fun userInfo(token: String?) {
//        if (token == null)
//            return
//
//        request(
//            { NetworkProxy.accountApi.getLoginUserInfo(token!!) },
//            {
//                appViewModel.loginUserInfo.value = it
//                loginUserInfo.value = it
//                goMain.value = true
//            },
//            { ToastProxy.showShort( R.string.description_failed_to_obtain_user_information) },
//            false,
//        )
    }

    fun exit() {
        viewModelScope.launch {
            runCatching {
                loadingChange.showDialog.postValue("")
                //请求体
                NetworkProxy.accountApi.exit()
            }.onSuccess {
                //网络请求成功 关闭弹窗
                loadingChange.dismissDialog.postValue(false)
                exitLMD.postValue(it.code == 0)
                Logcat.d(TAG, "退出 ${it.code == 0}")
            }.onFailure {
                //网络请求异常 关闭弹窗
                loadingChange.dismissDialog.postValue(false)
            }
        }
    }
}